package com.wanxi.service.impl;

import com.wanxi.dao.ProductDao;
import com.wanxi.dao.impl.ProductDaoImpl;
import com.wanxi.dto.ResultDTO;
import com.wanxi.model.ProductModel;
import com.wanxi.service.ProductService;

import java.util.List;

public class ProductServiceImpl implements ProductService {
    private ProductDao productDao = new ProductDaoImpl();

    public ResultDTO add(ProductModel model) {

        return ResultDTO.builder()
                .msg("")
                .code(0)
                .data(null)
                .count(productDao.add(model))
                .build();
    }

    public ResultDTO update(ProductModel model) {
        return ResultDTO.builder()
                .msg("")
                .code(0)
                .data(null)
                .count(productDao.update(model))
                .build();
    }

    public ResultDTO delete(ProductModel model) {
        return ResultDTO.builder()
                .msg("")
                .code(0)
                .data(null)
                .count(productDao.delete(model))
                .build();
    }

    public ResultDTO findById(ProductModel model) {
        return ResultDTO.builder()
                .msg("")
                .code(0)
                .count(0)
                .data(productDao.findById(model))
                .build();
    }

    public ResultDTO findAll(ProductModel model) {
        return ResultDTO.builder()
                .msg("")
                .code(0)
                .count(productDao.count(model))
                .data(productDao.findAll(model))
                .build();
    }


}
